<?php
namespace app\api\controller\v1\system;
use app\api\controller\v1\Init;

class Config extends Init
{
    public function _initialize() {
        parent::_initialize();
        $this->model = model('admin/config', 'service');
    }

    /* 配置列表 */
    public function lists(){
        $maps = [];
        if($this->params['keyword']) {
            $maps['nickname|province|city|country'] = ['like', '%'.$this->params['keyword'].'%'];
        }
        $info = $this->model->lists($maps, $this->params['limit'], $this->params['page']);
        return $this->response(lang('Operation completed'), $info);
    }

    /* 成员详情 */
    public function info() {
        $maps = [];
        $maps['id'] = $this->params['id'];
        $info = $this->model->get($maps);
        return $this->response(lang('Operation completed'), $info);
    }

    /* 成员添加 */
    public function add() {
        $post = $this->request->post();
        $result = $this->model->add($post, [], 'add');
        if($result === false) {
            return $this->response($this->model->getError());
        }
        return $this->response(lang('Operation completed'), $result);
    }

    /* 成员编辑 */
    public function edit() {
        $post = $this->request->post();
        $result = $this->model->edit($post, ['id' => $post['id']], 'edit');
        if($result === false) {
            return $this->response($this->model->getError());
        }
        return $this->response(lang('Operation completed'), $result);
    }

    /* 成员删除 */
    public function delete() {
        $id = $this->request->post('id/s');
        $ids = explode(",", $id);
        $maps = ['id' => ['in', $ids]];
        $result = $this->model->where($maps)->delete();
        if($result === false) {
            return $this->response($this->model->getError());
        }
        return $this->response(lang('Operation completed'), $result);
    }

}